package by.bsu.scs.util.runner;

import java.util.List;

import by.bsu.scs.db.dao.CourseHome;
import by.bsu.scs.db.dao.DisciplineHome;
import by.bsu.scs.db.dao.DisciplineInstructorHome;
import by.bsu.scs.db.dao.DisciplineStudentGroupHome;
import by.bsu.scs.db.dao.GroupHome;
import by.bsu.scs.db.dao.TaskAttachmentHome;
import by.bsu.scs.db.dao.UserHome;
import by.bsu.scs.model.Course;
import by.bsu.scs.model.Discipline;
import by.bsu.scs.model.Group;
import by.bsu.scs.model.TaskAttachment;
import by.bsu.scs.model.User;

/**
 * This class is for testing
 * 
 * @author Katherina_Prohorenko
 *
 */
public class TestQueryRunner {

	public static void main(String[] args) {
//		testFindDisciplineByInstructor();//ok
//		testFindStudentsByInstructorId();//ok
//		testFindStudentsByInstructorDisciplineGroupCourse();//ok
//		testFindStudentsByInstructorGroupCourse();//delete
//		testFindStudentsByInstructorDisciplineCourse();//ok
//		testFindStudentsByInstructorDisciplineGroup();//ok
//		testFindStudentsByInstructorDiscipline();//ok
//		testGetTaskAttachment();//ok
	}
	
	private static void testFindDisciplineByInstructor(){
		User exampleUser = new User();
		exampleUser.setUserId(37);
		
		DisciplineInstructorHome dao = new DisciplineInstructorHome();
		List<Discipline> disciplineList = dao.getDisciplineByInstructor(exampleUser);
		
		for(Discipline d:disciplineList){
			System.out.println(d.getDisciplineName());
			
		}
	}
	
	private static void testFindStudentsByInstructorId(){
		User exampleUser = new User();
		exampleUser.setUserId(40);
		
		DisciplineStudentGroupHome dao = new DisciplineStudentGroupHome();
		List<User> userListSQL = dao.getStudentsByInstructorIdSQL(exampleUser);
		for(User u:userListSQL){
			System.out.println(u.getUserName() +"\t"+ u.getEmail());
			
		}
	}
	
	private static void testFindStudentsByInstructorDisciplineGroupCourse(){
		User instructor = new UserHome().findById(30);
		Discipline discipline = new DisciplineHome().findById(8);
		Group group = new GroupHome().findById(6);
		
		DisciplineStudentGroupHome dao = new DisciplineStudentGroupHome();
		List<User> userListSQL = dao.getStudentsByInstructorDisciplineGroupCourseSQL(instructor, discipline, group);
		for(User u:userListSQL){
			System.out.println(u.getUserName() +"\t"+ u.getEmail());
			
		}
	}
	
	private static void testFindStudentsByInstructorDisciplineGroup(){
		User instructor = new UserHome().findById(30);
		Discipline discipline = new DisciplineHome().findById(7);
		Group group = new Group();
		group.setGroupNumber(6);
		
		DisciplineStudentGroupHome dao = new DisciplineStudentGroupHome();
		List<User> userListSQL = dao.getStudentsByInstructorDisciplineGroupSQL(instructor, discipline, group);
		for(User u:userListSQL){
			System.out.println(u.getUserName() +"\t"+ u.getEmail());
			
		}
	}
	
	private static void testFindStudentsByInstructorDisciplineCourse(){		
		User instructor = new UserHome().findById(30);
		Discipline discipline = new DisciplineHome().findById(8);
		Group group = new Group();
		group.setCourseId((new CourseHome().findById(2)));
		
		DisciplineStudentGroupHome dao = new DisciplineStudentGroupHome();
		List<User> userListSQL = dao.getStudentsByInstructorDisciplineCourseSQL(instructor, discipline, group);
		for(User u:userListSQL){
			System.out.println(u.getUserName() +"\t"+ u.getEmail());
			
		}
	}
	
	private static void testFindStudentsByInstructorGroupCourse(){
		User instructor = new User();
		instructor.setUserId(7);
		
		Group group = new Group();
		group.setGroupNumber(9);
		Course course = new Course();
		course.setCourseId(3);
		course.setCourseNumber(3);
		group.setCourseId(course);
		
		DisciplineStudentGroupHome dao = new DisciplineStudentGroupHome();
		List<User> userListSQL = dao.getStudentsByInstructorGroupCourseSQL(instructor,group);
		for(User u:userListSQL){
			System.out.println(u.getUserName() +"\t"+ u.getEmail());
			
		}
	}

	private static void testFindStudentsByInstructorDiscipline(){
		User instructor = new User();
		instructor.setUserId(30);
		
		Discipline discipline = new Discipline();
		discipline.setDisciplineId(7);
		
		DisciplineStudentGroupHome dao = new DisciplineStudentGroupHome();
		List<User> userListSQL = dao.getStudentsByInstructorDisciplineSQL(instructor,discipline);
		for(User u:userListSQL){
			System.out.println(u.getUserName() +"\t"+ u.getEmail());
			
		}
	}
	
	private static void testGetTaskAttachment() {
		TaskAttachmentHome dao = new TaskAttachmentHome();
		User u = new User();
		u.setUserId(30);
		List<TaskAttachment> modelList = dao.getTaskAttachmentByInstructorAndState(u, "unchecked");
		System.out.println(modelList.size());
	}
}
